package me.jessyan.mvparms.demo.mvp.ui.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.net.wifi.ScanResult;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.platform.ai.control.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.jessyan.mvparms.demo.mvp.model.entity.Device;
import me.jessyan.mvparms.demo.mvp.ui.holder.ItemClickListener;

/**
 * Created by 95 on 2017/9/5.
 */
public class ScanResultAdapter extends DefaultAdapter<ScanResult> {
    ConfigWIFIListener mListener;
    List<ScanResult> list;
    public ScanResultAdapter(List<ScanResult> infos,ConfigWIFIListener mListener) {
        super(infos);
        this.list = infos;
        this.mListener = mListener;
    }

    public void setList(List<ScanResult> list) {
        this.list = list;
    }

    @Override
    public ScanResult getItem(int position) {
        return list.get(position);
    }

    @Override
    public BaseHolder getHolder(View v, int viewType) {
        return new DeviceHolder(v,mListener);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_scan_result;
    }

    public class DeviceHolder extends BaseHolder<ScanResult> {

        @BindView(R.id.ssid)
        TextView mWifiName;

        @BindView(R.id.level)
        TextView mWifiLevel;

        private View mView;

        ConfigWIFIListener mListener;
        public DeviceHolder(View itemView,ConfigWIFIListener mListener) {
            super(itemView);
            this.mListener = mListener;
        }


        @SuppressLint("StringFormatInvalid")
        @Override
        public void setData(ScanResult scanResult, int position) {
            mView = itemView;
            mWifiName.setText(" SSID: "+scanResult.SSID);
            mWifiLevel.setText(" 信号: "+scanResult.level);

            mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.configBySSIDAndPwd(scanResult);
                }
            });
        }
    }

    public interface ConfigWIFIListener{
        void configBySSIDAndPwd(ScanResult sr);
    }

}
